home *** CD-ROM | disk | FTP | other *** search
/ ftp.qualcomm.com / 2014.06.ftp.qualcomm.com.tar / ftp.qualcomm.com / eudora / developers / emsapi / carbon_emsapi.sit.hqx / Macintosh API Support / emsapi-component.c < prev    next >
C/C++ Source or Header  |  2001-03-08  |  11KB  |  346 lines

  1. /* ======================================================================
  2.  
  3.     Component Manager glue for EMSAPI version 3
  4.  
  5.     Filename:            emsapi-component.c
  6.     Last Edited:        March 7, 1997
  7.     Authors:            Laurence Lundblade, Bob Fronabarger
  8.     Copyright:            1995, 1996 QUALCOMM Inc.
  9.     Technical support:    <emsapi-info@qualcomm.com>
  10.  
  11.     THIS FILE SHOULD BE COMPILED ALONG WITH THE COMPONENT
  12.     BE SURE YOU SUPPLY A usertrans.h WHEN YOU COMPILE IT
  13. */
  14.  
  15. #include <A4Stuff.h>
  16. #include "emsapi-mac.h"
  17. #include "usertrans.h"
  18.  
  19. #define HiWord(x) ((short)((long)(x) >> 16))
  20. #define LoWord(x) ((short)(x))
  21.  
  22. typedef enum {
  23.     kems_plugin_versionRtn = 256,
  24.     kems_plugin_initRtn = 257,
  25.     kems_translator_infoRtn = 258,
  26.     kems_can_translateRtn = 259,
  27.     kems_translate_fileRtn = 260,
  28.     kems_plugin_finishRtn = 261,
  29.     kems_plugin_configRtn = 262,
  30.     kems_queued_propertiesRtn = 263,
  31.     kems_attacher_infoRtn = 264,
  32.     kems_attacher_hookRtn = 265,
  33.     kems_special_infoRtn = 266,
  34.     kems_special_hookRtn = 267,
  35.     kems_idleRtn = 268,
  36.     kems_mbox_context_infoRtn = 269,
  37.     kems_mbox_context_hookRtn = 270,
  38. // start MODELESS EMSAPI
  39.     kems_plugwindow_closeRtn,
  40.     kems_plugwindow_reopenRtn,
  41.     kems_plugwindow_eventRtn,
  42.     kems_plugwindow_menu_enableRtn,
  43.     kems_plugwindow_menuRtn,
  44.     kems_plugwindow_dragRtn,
  45. // end MODELESS EMSAPI
  46.     kems_importer_infoRtn,
  47.     kems_importer_hookRtn
  48. } kemsRtn;
  49.  
  50. #ifdef __cplusplus
  51. extern "C" {
  52. #endif
  53.  
  54. /* ----------------------------------------------------------------------
  55.     Declarations of real functions that handle the standard
  56.     housekeeping calls of any component.
  57.  */
  58. pascal ComponentResult  FatOpen(ComponentInstance self);
  59. pascal ComponentResult  FatClose(Handle storage, ComponentInstance self);
  60. pascal ComponentResult  FatCanDo(short selector);
  61. pascal ComponentResult  FatVersion(void);
  62. pascal ComponentResult  main(ComponentParameters *params, Handle storage);
  63.  
  64.  
  65. static Component    gSelfSave;
  66.  
  67. #ifdef __powerc
  68. #if !TARGET_API_MAC_CARBON
  69. RoutineDescriptor MainRD = BUILD_ROUTINE_DESCRIPTOR(uppComponentRoutineProcInfo, main);
  70. ProcInfoType __procinfo = uppComponentRoutineProcInfo;
  71. #endif
  72. #endif
  73.  
  74. /* ----------------------------------------------------------------------
  75.     This is the main entry point for the component. The calls for the
  76.     component functions below are really gigantic horrible macros that
  77.     do weird things
  78.  
  79.     The return values that Eudora actually sees are the translation API return
  80.     values (EMSR_XXXX) in the case of an API call, and Macintosh system error
  81.     in the case of one of the four Component Manager-specific calls.
  82.  */
  83. pascal ComponentResult main(ComponentParameters *params, Handle storage)
  84. {
  85.     ComponentResult        result = noErr;
  86.     short                resRef, saveRes;
  87.  
  88.     EnterCodeResource();
  89.     if (params->what < 0) 
  90.     {        // Component Manager request code
  91.         switch (params->what) 
  92.         {
  93.             case kComponentOpenSelect:
  94.                 result = FatOpen((ComponentInstance)params->params[0]);
  95.                 break;
  96.             case kComponentCloseSelect:
  97.                 result = FatClose(storage,(ComponentInstance)params->params[0]);
  98.                 break;
  99.             case kComponentCanDoSelect:
  100.                 result = FatCanDo(HiWord(params->params[0]));
  101.                 break;
  102.             case kComponentVersionSelect:
  103.                 result = FatVersion();
  104.                 break;
  105.         //    case kComponentRegisterSelect:  // not supported
  106.             default:
  107.                 result = paramErr;
  108.                 break;
  109.         }
  110.     }
  111.     else 
  112.     {                        // Our request code
  113.         saveRes = CurResFile();
  114.         resRef = OpenComponentResFile(gSelfSave);
  115.         if (resRef < 0)
  116.             return EMSR_TRANS_FAILED;
  117.         UseResFile(resRef);
  118.         switch (params->what) 
  119.         {
  120.             case kems_plugin_versionRtn:
  121.                 result = ems_plugin_version(storage,(short*)params->params[0]);
  122.                 break;
  123.             case kems_plugin_initRtn:
  124.                 result = ems_plugin_init(storage,(short)params->params[2],(emsMailConfigP)params->params[1],(emsPluginInfoP)params->params[0]);
  125.                 break;
  126.             case kems_plugin_finishRtn:
  127.                 result = ems_plugin_finish(storage);
  128.                 break;
  129. #if EMS_HAS_TRANSLATOR_INFO
  130.             case kems_translator_infoRtn:
  131.                 result = ems_translator_info(storage,(emsTranslatorP)params->params[0]);
  132.                 break;
  133. #endif
  134. #if EMS_HAS_CAN_TRANSLATE
  135.             case kems_can_translateRtn:
  136.                 result = ems_can_translate(storage,(emsTranslatorP)params->params[2],(emsDataFileP)params->params[1],(emsResultStatusP)params->params[0]);
  137.                 break;
  138. #endif
  139. #if EMS_HAS_TRANSLATE_FILE
  140.             case kems_translate_fileRtn:
  141.                 result = ems_translate_file(storage,(emsTranslatorP)params->params[4],(emsDataFileP)params->params[3],(emsProgress)params->params[2],(emsDataFileP)params->params[1],(emsResultStatusP)params->params[0]);
  142.                 break;
  143. #endif
  144. #if EMS_HAS_PLUGIN_CONFIG
  145.             case kems_plugin_configRtn:
  146.                 result = ems_plugin_config(storage,(emsMailConfigP)params->params[0]);
  147.                 break;
  148. #endif
  149. #if EMS_HAS_QUEUED_PROPERTIES
  150.             case kems_queued_propertiesRtn:
  151.                 result = ems_queued_properties(storage,(emsTranslatorP)params->params[1],(long*)params->params[0]);
  152.                 break;
  153. #endif
  154. #if EMS_HAS_ATTACHER_INFO
  155.             case kems_attacher_infoRtn:
  156.                 result = ems_attacher_info(storage,(emsMenuP)params->params[0]);
  157.                 break;
  158. #endif
  159. #if EMS_HAS_ATTACHER_HOOK
  160.             case kems_attacher_hookRtn:
  161.                 result = ems_attacher_hook(storage,(emsMenuP)params->params[3],(FSSpec *)params->params[2],(long *)params->params[1],(emsDataFileH)params->params[0]);
  162.                 break;
  163. #endif
  164. #if EMS_HAS_SPECIAL_INFO
  165.             case kems_special_infoRtn:
  166.                 result = ems_special_info(storage,(emsMenuP)params->params[0]);
  167.                 break;
  168. #endif
  169. #if EMS_HAS_SPECIAL_HOOK
  170.             case kems_special_hookRtn:
  171.                 result = ems_special_hook(storage,(emsMenuP)params->params[0]);
  172.                 break;
  173. #endif
  174. #if EMS_HAS_IDLE
  175.             case kems_idleRtn:
  176.                 result = ems_idle(storage,(emsIdleDataP)params->params[0]);
  177.                 break;
  178. #endif
  179. #if EMS_HAS_MBOX_CONTEXT_INFO
  180.             case kems_mbox_context_infoRtn:
  181.                 result = ems_mbox_context_info(storage,(emsMenuP)params->params[0]);
  182.                 break;
  183. #endif
  184. #if EMS_HAS_MBOX_CONTEXT_HOOK
  185.             case kems_context_hookRtn:
  186.                 result = ems_context_hook(storage,(emsMenuP)params->params[0]);
  187.                 break;
  188. #endif
  189. #if EMS_HAS_PLUGWINDOW
  190.             case kems_plugwindow_closeRtn:
  191.                 result = ems_plugwindow_close(storage,(emsPlugwindowDataP)params->params[0]);
  192.                 break;
  193.             case kems_plugwindow_reopenRtn:
  194.                 result = ems_plugwindow_reopen(storage,(emsPlugwindowDataP)params->params[0]);
  195.                 break;
  196.             case kems_plugwindow_eventRtn:
  197.                 result = ems_plugwindow_event(storage,(emsPlugwindowDataP)params->params[1],(emsPlugwindowEventP)params->params[0]);
  198.                 break;
  199.             case kems_plugwindow_menu_enableRtn:
  200.                 result = ems_plugwindow_menu_enable(storage,(emsPlugwindowDataP)params->params[1],(emsPlugwindowEventP)params->params[0]);
  201.                 break;
  202.             case kems_plugwindow_menuRtn:
  203.                 result = ems_plugwindow_menu(storage,(emsPlugwindowDataP)params->params[1],(emsPlugwindowEventP)params->params[0]);
  204.                 break;
  205.             case kems_plugwindow_dragRtn:
  206.                 result = ems_plugwindow_drag(storage,(emsPlugwindowDataP)params->params[1],(emsPlugwindowDragDataP)params->params[0]);
  207.                 break;
  208. #endif
  209. #if EMS_HAS_IMPORTER_INFO
  210.             case kems_importer_infoRtn:
  211.                 result = ems_importer_info(storage,(emsImporterP)params->params[0]);
  212.                 break;
  213. #endif
  214. #if EMS_HAS_IMPORTER_HOOK
  215.             case kems_importer_hookRtn:
  216.                 result = ems_importer_hook(storage,(emsImporterDataP)params->params[0]);
  217.                 break;
  218. #endif
  219.             default:
  220.                 result = EMSR_TRANS_FAILED;
  221.                 break;
  222.         }
  223.         CloseComponentResFile(resRef);
  224.         UseResFile(saveRes);
  225.     }
  226.     ExitCodeResource();
  227.     return result;
  228. }
  229.  
  230.  
  231. /* ----------------------------------------------------------------------
  232.     Standard component function to open a component
  233.  */
  234. pascal ComponentResult FatOpen(ComponentInstance self)
  235. {
  236.     ComponentResult     result = noErr;
  237.     emsUserGlobals** globals;
  238.  
  239.     globals = (emsUserGlobals**) NewHandleClear(sizeof(emsUserGlobals));
  240.     if (globals != nil) {
  241.         (**globals).self = (Component) self;    // remember ourselves
  242.         gSelfSave = (Component) self;
  243.  
  244.         // tell the component manager that we have global storage
  245.         SetComponentInstanceStorage(self, (Handle) globals);
  246.     }
  247.     else
  248.         result = MemError();
  249.  
  250.     return result;
  251. }
  252.  
  253.  
  254. /* ----------------------------------------------------------------------
  255.     Standard component function to close a component
  256.  */
  257. pascal ComponentResult FatClose(Handle storage, ComponentInstance self)
  258. {
  259.     ComponentResult     result = noErr;
  260.     emsUserGlobals** globals = (emsUserGlobals**) storage;
  261.  
  262.     if (globals != nil) {
  263.         DisposeHandle((Handle) globals);
  264.         globals = nil;
  265.     }
  266.     return result;
  267. }
  268.  
  269.  
  270. /* ----------------------------------------------------------------------
  271.     Standard component function to test availability of a function
  272.     The EMS_HAS_xxx constants are supplied by the translator writer
  273.     in the file usertrans.h
  274.  */
  275. pascal ComponentResult FatCanDo(short selector)
  276. {
  277.     switch (selector) {                    // component Manager request codes
  278.         case kComponentOpenSelect:
  279.         case kComponentCloseSelect:
  280.         case kComponentCanDoSelect:
  281.         case kComponentVersionSelect:
  282.     //    case kComponentRegisterSelect:  // not supported
  283.             return true;
  284.         case kems_plugin_versionRtn:
  285.             return EMS_HAS_PLUGIN_VERSION;
  286.         case kems_plugin_initRtn:
  287.             return EMS_HAS_PLUGIN_INIT;
  288.         case kems_translator_infoRtn:
  289.             return EMS_HAS_TRANSLATOR_INFO;
  290.         case kems_can_translateRtn:
  291.             return EMS_HAS_CAN_TRANSLATE;
  292.         case kems_translate_fileRtn:
  293.             return EMS_HAS_TRANSLATE_FILE;
  294.         case kems_plugin_finishRtn:
  295.             return EMS_HAS_PLUGIN_FINISH;
  296.         case kems_plugin_configRtn:
  297.             return EMS_HAS_PLUGIN_CONFIG;
  298.         case kems_queued_propertiesRtn:
  299.             return EMS_HAS_QUEUED_PROPERTIES;
  300.         case kems_attacher_infoRtn:
  301.             return EMS_HAS_ATTACHER_INFO;
  302.         case kems_attacher_hookRtn:
  303.             return EMS_HAS_ATTACHER_HOOK;
  304.         case kems_special_infoRtn:
  305.             return EMS_HAS_SPECIAL_INFO;
  306.         case kems_special_hookRtn:
  307.             return EMS_HAS_SPECIAL_HOOK;
  308.     case kems_idleRtn:
  309.         return EMS_HAS_IDLE;
  310.     case kems_mbox_context_infoRtn:
  311.         return EMS_HAS_MBOX_CONTEXT_INFO;
  312.     case kems_mbox_context_hookRtn:
  313.         return EMS_HAS_MBOX_CONTEXT_HOOK;
  314.     case kems_plugwindow_closeRtn:
  315.     case kems_plugwindow_reopenRtn:
  316.     case kems_plugwindow_eventRtn:
  317.        case kems_plugwindow_menu_enableRtn:
  318.        case kems_plugwindow_menuRtn:
  319.     case kems_plugwindow_dragRtn:
  320.         return EMS_HAS_PLUGWINDOW;
  321.     case kems_importer_infoRtn:
  322.         return EMS_HAS_IMPORTER_INFO;
  323.     case kems_importer_hookRtn:
  324.         return EMS_HAS_IMPORTER_HOOK;
  325.         default:                        // unknown request
  326.             return false;
  327.     }
  328. }
  329.  
  330.  
  331. /* ----------------------------------------------------------------------
  332.     Standard component function to return the components version
  333.     The version number here is maintained in parallel with the
  334.     API version number.  The high 16 bits are the API version,
  335.     and the low 16 are the component implementation version (unused).
  336.  */
  337. pascal ComponentResult FatVersion(void)
  338. {
  339.     return EMS_VERSION << 16;
  340. }
  341.  
  342.  
  343. #ifdef __cplusplus
  344. }
  345. #endif
  346.